home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / src / lib / gprim / bbox / bboxdraw.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-25  |  1.9 KB  |  67 lines

  1. /* Copyright (c) 1992 The Geometry Center; University of Minnesota
  2.    1300 South Second Street;  Minneapolis, MN  55454, USA;
  3.    
  4. This file is part of geomview/OOGL. geomview/OOGL is free software;
  5. you can redistribute it and/or modify it only under the terms given in
  6. the file COPYING, which you should have received along with this file.
  7. This and other related software may be obtained via anonymous ftp from
  8. geom.umn.edu; email: software@geom.umn.edu. */
  9.  
  10. /* Authors: Charlie Gunn, Stuart Levy, Tamara Munzner, Mark Phillips */
  11.  
  12. #include "mg.h"
  13. #include "bboxP.h"
  14.  
  15. BBox *
  16. BBoxDraw(bbox)
  17.      register BBox *bbox;
  18. {
  19.     register int i, k, numvert;
  20.     int dimn;
  21.     HPoint3 vert[16];
  22.     Color *edgecolor;
  23.     Appearance *ap = mggetappearance();
  24.  
  25.     if(!(ap->flag & APF_EDGEDRAW))
  26.     return bbox;
  27.  
  28.     dimn = (bbox->geomflags & VERT_4D) ? 4 : 3;
  29.     if (dimn == 3)    {    /* dehomogenize min, max vals */
  30.     HPt3Normalize(&bbox->min, &bbox->min);
  31.     HPt3Normalize(&bbox->max, &bbox->max);
  32.     }
  33.  
  34.     /* fill in the vertices of the (hyper) cube */
  35.     for(i = 0; i < (1 << dimn); i++) {
  36.     vert[i].x = i&1 ? bbox->min.x : bbox->max.x;
  37.     vert[i].y = i&2 ? bbox->min.y : bbox->max.y;
  38.     vert[i].z = i&4 ? bbox->min.z : bbox->max.z;
  39.     vert[i].w = i&8 ? bbox->min.w : bbox->max.w;
  40.     }
  41.  
  42.     numvert = 1 << dimn;
  43.  
  44.     /* turn on the edge color to draw the bbox */
  45.  
  46.     edgecolor = &ap->mat->edgecolor;
  47.     for(i = 0; i < numvert; i++) {
  48.     int j, incr;
  49.     HPoint3 edge[2];
  50.  
  51.     for(j = 0; j < dimn; j ++) {
  52.         /* connect this vertex to its nearest neighbors if they
  53.          * follow it in lexicographical order */
  54.         incr = 1 << j;
  55.         /* is the j_th bit a zero? */
  56.         if ( ! (i & incr) )    {
  57.         /* if so, draw the edge to the vertex whose number is
  58.          * gotten from i by making the j_th bit a one */
  59.         edge[0] = vert[i];
  60.         edge[1] = vert[i + incr];
  61.         mgpolyline(2, edge, 1,  edgecolor, 0) ;
  62.         }
  63.     }
  64.     }
  65.     return bbox;
  66. }
  67.